﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmInplaceEdit.h"
#include "IEditModeBehavior.h"
#include "DbDataSchema.h"
#include "IEditMode.h"


namespace gcmp
{
    class GM_INPLACE_EDIT_EXPORT InplaceEditModeBehavior : public gcmp::NdbObjectSchematic, public gcmp::IEditModeBehavior
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, InplaceEditModeBehavior, gcmp::NdbObjectSchematic, 834A04FF - 6205 - 4864 - B8E4 - D2621BCDF011, gminplaceedit, gcmp::IEditModeBehavior)
            MAP_DATA(Int64, ElementId, ProjectIdToReferenceElementIds)
            DATA(UInt16, ProjectAppPort)
        DBOBJECT_DATA_END

    public:
        static const std::wstring InplaceEditModeType;

    public:
        static gcmp::IEditMode* Create(gcmp::IDocument* pDoc);
        static bool IsInEditMode(gcmp::IDocument* pDoc);
        static const InplaceEditModeBehavior* Get(gcmp::IDocument* pDoc);
        static InplaceEditModeBehavior* GetFw(gcmp::IDocument* pDoc);

        virtual bool StartEditing(gcmp::IDocument* pDoc, bool isCreating) override;
        virtual bool EndEditing(gcmp::IDocument* pDoc) override;

        ElementId GetReferenceElementId(Int64 projectElementId) const;
        void AddReferenceElement(ElementId referenceElementId, Int64 projectElementId);

        uint16_t GetProjectAppPort() const { return GetProjectAppPort__(); }
        void SetProjectAppPort(uint16_t port) { SetProjectAppPort__(port); }

    public:
        virtual std::wstring GetEditModeType() const override { return InplaceEditModeType; }
        virtual bool IsElementEditable(const gcmp::IElement* pElement) const override;
        virtual bool IsNotAffectedByViewRange(const gcmp::IElement* pElement) const override { return false; }

        virtual void ReportParents(gcmp::IDocument* pDoc, gcmp::IElementParentReporter& reporter) const override;
        virtual void UpdateForWeakParentDeletion(gcmp::IDocument* pDoc, const std::set<gcmp::ElementId>& deletedElementIds) override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };
}

